package fhp.hlhj.giantfold.activity.orders

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
import android.support.v4.view.ViewPager
import fhp.hlhj.giantfold.BaseActivity
import fhp.hlhj.giantfold.R
import fhp.hlhj.giantfold.adapter.ViewPagerAdp
import fhp.hlhj.giantfold.customView.OrderPop
import fhp.hlhj.giantfold.fragment.OrderFgm
import fhp.hlhj.giantfold.fragment.TicketOrderFgm
import kotlinx.android.synthetic.main.activity_order_aty.*

class TiketAty : BaseActivity(), ViewPager.OnPageChangeListener, TabLayout.OnTabSelectedListener {

    private lateinit var pagerAdp: ViewPagerAdp

    override fun getContentId(): Int = R.layout.activity_tiket_aty
    private var fragments=ArrayList<Fragment>()
    private lateinit var allFgm: TicketOrderFgm
    private lateinit var goingFgm: TicketOrderFgm
    private lateinit var savedFgm: TicketOrderFgm
    private lateinit var uselessFgm: TicketOrderFgm

    override fun initView() {

        allFgm= TicketOrderFgm.newInstence("全部")
        goingFgm= TicketOrderFgm.newInstence("进行中")
        savedFgm= TicketOrderFgm.newInstence("已存入")
        uselessFgm=TicketOrderFgm.newInstence("已失效")
        fragments.add(allFgm)
        fragments.add(goingFgm)
        fragments.add(savedFgm)
        fragments.add(uselessFgm)
        pagerAdp= ViewPagerAdp(supportFragmentManager,fragments)

        viewPager.adapter=pagerAdp

    }

    override fun initListener() {
        viewPager.addOnPageChangeListener(this)
        tabLayout.addOnTabSelectedListener(this)
        btExit.setOnClickListener {
            finish()
        }

    }
    override fun onPageScrollStateChanged(state: Int) {
    }

    override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
    }

    override fun onPageSelected(position: Int) {
        tabLayout.getTabAt(position)?.select()
    }

    override fun onTabReselected(tab: TabLayout.Tab?) {
    }

    override fun onTabUnselected(tab: TabLayout.Tab?) {
    }

    override fun onTabSelected(tab: TabLayout.Tab?) {
        val position = tab?.position
        if (position != null) {
            viewPager.currentItem = position
        }
    }
}
